import wepy from 'wepy'
export default class extends wepy.mixin {
    data = {
        // 分类列表
        cateList: [],
        // 控制选中第几项
        activeKey: 0,
        // 当前屏幕可用高度
        wh: 0,
        // 二级数据列表
        secondData: []
    }
    onLoad() {
        this.getCateList()
        this.getWindowHeight()
    }
    methods = {
        onChange(e) {
            // 获取索引
            console.log(e.detail)
            this.secondData = this.cateList[e.detail].children
            console.log(this.secondData)
        },
        goGoodList(cid) {
            wepy.navigateTo({
                url: '/pages/goods_list?cid=' + cid
            })
        }
    }

    async getCateList() {
        const { data: res } = await wepy.get('/categories')
        if (res.meta.status !== 200) {
            return wepy.baseToast()
        }
        this.cateList = res.message
        this.secondData = res.message[0].children
        console.log(this.secondData)
        this.$apply()
    }

    async getWindowHeight() {
        const res = await wepy.getSystemInfo()
        if (res.errMsg === 'getSystemInfo:ok') {
            this.wh = res.windowHeight
            this.$apply()
        }
    }
}